//
//  NSString+GXBase64.m
//  24-加密
//
//  Created by Snow on 16/8/16.
//  Copyright © 2016年 Snow. All rights reserved.
//

#import "NSString+GXBase64.h"

@implementation NSString (GXBase64)
//编码
- (NSString *)stringWithBase64
{
    NSData *stringData = [self dataUsingEncoding:NSUTF8StringEncoding];//字符串转Data
    NSString *base64string = [stringData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];//data进行base64
    return base64string;
    
}
- (NSData *)base64StringWithData
{
    return [[NSData alloc] initWithBase64EncodedString:self options:NSDataBase64DecodingIgnoreUnknownCharacters];
}
//解码
- (NSString *)Base64WithString
{
    NSData *base64data = [[NSData alloc] initWithBase64EncodedString:self options:NSDataBase64DecodingIgnoreUnknownCharacters];//base64转data
    NSString *originstring = [[NSString alloc] initWithData:base64data encoding:NSUTF8StringEncoding];//根据data生成字符串
    return originstring;
}

@end
